class UserModel {
  final int uid;  // 改为 int 类型
  final int showId;  // 改为 int 类型，使用驼峰命名
  final String nickname;  // 添加 nickname 字段
  final int isNew;  // 保持 int 类型
  final int loginType;  // 添加 loginType 字段
  final int couponHistory;  // 保持 int 类型
  final String email;  // 添加 email 字段
  final String accessToken;  // 改为驼峰命名
  final String user_key;

  UserModel({
    required this.uid,
    required this.showId,
    required this.nickname,
    required this.isNew,
    required this.loginType,
    required this.couponHistory,
    required this.email,
    required this.accessToken,
    required this.user_key,
  });

  factory UserModel.fromJson(Map<String, dynamic> json) {
    return UserModel(
      uid: json['uid'] ?? 0,
      showId: json['show_id'] ?? 0,
      nickname: json['nickname'] ?? '',
      isNew: json['is_new'] ?? 0,
      loginType: json['login_type'] ?? 0,
      couponHistory: json['coupon_history'] ?? 0,
      email: json['email'] ?? '',
      accessToken: json['access_token'] ?? '',
      user_key: json['user_key'] ?? '',
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'uid': uid,
      'show_id': showId,
      'nickname': nickname,
      'is_new': isNew,
      'login_type': loginType,
      'coupon_history': couponHistory,
      'email': email,
      'access_token': accessToken,
      'user_key': user_key,
    };
  }

  // 便捷方法
  bool get isNewUser => isNew == 1;
  bool get hasValidToken => accessToken.isNotEmpty;
  bool get hasEmail => email.isNotEmpty;
  String get displayName => nickname.isNotEmpty ? nickname : 'User$showId';
}